import store from 'store2'
import MD5 from 'md5'

export function getCach({ url, param }) {
	let cachData = store.session.get('cachData') || []
		, returnData = _.findWhere(cachData, { id: MD5(`${url}${param}`) })
	if (returnData && returnData.data) {
		return new Promise(resolve => {
			resolve(returnData.data)
		})
	}
}

export function setCach({ url, param }, data) {
	let cachData = store.session.get('cachData') || [];
	cachData.push({
		id: MD5(`${url}${param}`),
		name: MD5(`${url}`),
		data
	})
	store.session.set("cachData", cachData)
	return new Promise(resolve => {
		resolve(data)
	})
}

// export function deleteCach(url) {
// 	let cachData = store.session.get('cachData') || []
// 		, findData = _.findWhere(cachData, { name: MD5(url) })
// }